package com.firewolf.cloud.controller;

import com.test.entities.User;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.List;


@RestController
@RequestMapping("user")
public class UserController {

    @PostMapping
    public String add(@RequestBody User u) {
        System.out.println(u);
        return "add ok";
    }

    @PostMapping("add")
    public String add(String name,Integer age){
        System.out.println(name+","+age);
        return "add ok";
    }


    @DeleteMapping("/{id}")
    public String delete(@PathVariable("id") Integer uid) {
        System.out.println(uid);
        return "delete ok";
    }

    @PutMapping
    public String update(@RequestBody User u) {
        System.out.println(u);
        return "update ok";
    }


    @GetMapping
    public List<User> list(String name, Integer age) {
        System.out.println(name + "," + age);
        return Arrays.asList(new User(1, "lx", 31, new Date()), new User(2, "lxx", 32, new Date()));
    }

    @GetMapping("list")
    public List<User> list2(@RequestBody User u) {
        System.out.println(u);
        return Arrays.asList(new User(1, "lx", 31, new Date()), new User(2, "lxx", 32, new Date()));
    }
}
